/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.entities;

import cse308.GeneralEntity;
import cse308.helper_classes.GeneralTest;
import cse308.helper_classes.PEOClass;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Aaron
 */
@Entity
@Table(catalog = "nchorn", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Peo.findAll", query = "SELECT p FROM Peo p"),
    @NamedQuery(name = "Peo.findByIdentifier", query = "SELECT p FROM Peo p WHERE p.identifier = :identifier"),
    @NamedQuery(name = "Peo.findBySeqNum", query = "SELECT p FROM Peo p WHERE p.seqNum = :seqNum"),
    @NamedQuery(name = "Peo.findByShortname", query = "SELECT p FROM Peo p WHERE p.shortname = :shortname"),
    @NamedQuery(name = "Peo.findByDescription", query = "SELECT p FROM Peo p WHERE p.description = :description"),
    @NamedQuery(name = "Peo.findBySemster", query = "SELECT p FROM Peo p WHERE p.semster = :semster"),
    @NamedQuery(name = "Peo.findByYea", query = "SELECT p FROM Peo p WHERE p.yea = :yea"),
    @NamedQuery(name = "Peo.findByEndsemester", query = "SELECT p FROM Peo p WHERE p.endsemester = :endsemester"),
    @NamedQuery(name = "Peo.findByEndyear", query = "SELECT p FROM Peo p WHERE p.endyear = :endyear"),
    @NamedQuery(name = "Peo.findByDegreeProgramAlt", query = "SELECT p FROM Peo p WHERE p.degreeProgramAlt = :degreeProgramAlt"),
    @NamedQuery(name = "Peo.findByDegreeProgramString", query = "SELECT p FROM Peo p WHERE p.degreeProgramString.identifier = :degreeProgramString")
})
public class Peo implements Serializable, GeneralEntity {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(nullable = false, length = 20)
    private String identifier;
    private Integer seqNum;
    @Size(max = 5)
    @Column(length = 5)
    private String shortname;
    @Size(max = 120)
    @Column(length = 120)
    private String description;
    private Integer semster;
    private Integer yea;
    private Integer endsemester;
    private Integer endyear;
    @Size(max = 20)
    @Column(length = 20)
    private String degreeProgramAlt;
    @JoinColumn(name = "degreeProgramString", referencedColumnName = "identifier")
    @ManyToOne
    private Degreeprogram degreeProgramString;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "peo1")
    private Collection<Targetattainmentlevel> targetattainmentlevelCollection;
    @OneToMany(mappedBy = "peoIdentifier")
    private Collection<Peoattainment> peoattainmentCollection;

    public Peo() {
        this.targetattainmentlevelCollection = new ArrayList();
        this.peoattainmentCollection = new ArrayList();

    }

    public Peo(String identifier) {
        this.identifier = identifier;
        this.targetattainmentlevelCollection = new ArrayList();
        this.peoattainmentCollection = new ArrayList();
    }

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public Integer getSeqNum() {
        return seqNum;
    }

    public void setSeqNum(Integer seqNum) {
        this.seqNum = seqNum;
    }

    public String getShortname() {
        return shortname;
    }

    public void setShortname(String shortname) {
        this.shortname = shortname;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getSemster() {
        return semster;
    }

    public void setSemster(Integer semster) {
        this.semster = semster;
    }

    public Integer getYea() {
        return yea;
    }

    public void setYea(Integer yea) {
        this.yea = yea;
    }

    public Integer getEndsemester() {
        return endsemester;
    }

    public void setEndsemester(Integer endsemester) {
        this.endsemester = endsemester;
    }

    public Integer getEndyear() {
        return endyear;
    }

    public void setEndyear(Integer endyear) {
        this.endyear = endyear;
    }

    public String getDegreeProgramAlt() {
        return degreeProgramAlt;
    }

    public void setDegreeProgramAlt(String degreeProgramAlt) {
        this.degreeProgramAlt = degreeProgramAlt;
    }

    public Degreeprogram getDegreeProgramString() {
        return degreeProgramString;
    }

    public void setDegreeProgramString(Degreeprogram degreeProgramString) {
        this.degreeProgramString = degreeProgramString;
    }

    @XmlTransient
    public Collection<Targetattainmentlevel> getTargetattainmentlevelCollection() {
        return targetattainmentlevelCollection;
    }

    public void setTargetattainmentlevelCollection(Collection<Targetattainmentlevel> targetattainmentlevelCollection) {
        this.targetattainmentlevelCollection = targetattainmentlevelCollection;
    }

    @XmlTransient
    public Collection<Peoattainment> getPeoattainmentCollection() {
        return peoattainmentCollection;
    }

    public void setPeoattainmentCollection(Collection<Peoattainment> peoattainmentCollection) {
        this.peoattainmentCollection = peoattainmentCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (identifier != null ? identifier.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Peo)) {
            return false;
        }
        Peo other = (Peo) object;
        if ((this.identifier == null && other.identifier != null) || (this.identifier != null && !this.identifier.equals(other.identifier))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cse308.entities.Peo[ identifier=" + identifier + " ]";
    }

    @Override
    public List<List<GeneralEntity>> getAssociatedClasses() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<GeneralEntity> getAssociatedClass(String associated) {
        ArrayList<GeneralEntity> toReturn = new ArrayList();
        if (associated.equals(Degreeprogram.class.getSimpleName())) {
            toReturn.add(this.degreeProgramString);
        }
        return toReturn;
    }

    @Override
    public void setWithClass(GeneralTest gt) {
        /*
         *  this.identifier = entity.getIdentifier();
         this.seqNum = entity.getSeqNum();
         this.shortname = entity.getShortname();
         this.description = entity.getDescription();
         this.year = entity.getYear();
         this.semster = entity.getSemster();
         */
        PEOClass peo = (PEOClass) gt;
        this.identifier = peo.getIdentifier();
        this.seqNum = peo.getSeqNum();
        this.shortname = peo.getShortname();
        this.description = peo.getDescription();
        this.yea = peo.getYea();
        this.semster = peo.getSemster();
    }

    @Override
    public void testAddClass(GeneralEntity ge) {
        if (ge instanceof Degreeprogram) {
            this.degreeProgramString = (Degreeprogram) ge;
        } else if (ge instanceof Targetattainmentlevel) {
            this.targetattainmentlevelCollection.add((Targetattainmentlevel) ge);
        }
    }

    @Override
    public void removeClass(GeneralEntity ge) {
        if (ge instanceof Degreeprogram) {
            this.degreeProgramString = null;
        } else if (ge instanceof Targetattainmentlevel) {
            this.targetattainmentlevelCollection.remove((Targetattainmentlevel) ge);
        }
    }

    @Override
    public String getIdentifier2() {
        return this.identifier;
    }

    @Override
    public GeneralEntity findCorrespondingEntity() {
        return this;
    }

    @Override
    public boolean equalsEntity(GeneralEntity entity) {
        return this.equals(entity);
    }

    @Override
    public Object getPK() {
        return this.identifier;
    }
}
